package com.atguigu.test.rabbitmq.controller;

import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
public class CreateMq {
    @Autowired
    AmqpAdmin amqpAdmin;

    @GetMapping("/create1")
    @ResponseBody
    public String createMq(){
        //String name, boolean durable, boolean autoDelete, Map<String, Object> arguments
        DirectExchange directExchange = new DirectExchange("two-java-exchange", true, false, new HashMap<String, Object>());
        amqpAdmin.declareExchange(directExchange);
        return "ok";
    }
    @GetMapping("/create2")
    @ResponseBody
    public String createQueue(){
//        String name,
//        boolean durable,
//        boolean exclusive,
//        boolean autoDelete,
//        @Nullable Map<String, Object> arguments
        Queue queue = new Queue("two-java-queue", true, false, false);
        amqpAdmin.declareQueue(queue);
        return "queeue-ok";
    }

    @GetMapping("/create3")
    @ResponseBody
    public String createBinding(){
//        String destination, DestinationType destinationType, String exchange, String routingKey,
//                @Nullable Map<String, Object> arguments
        Binding binding = new Binding("two-java-queue", Binding.DestinationType.QUEUE, "two-java-exchange", "two.java", new HashMap<String, Object>());
        amqpAdmin.declareBinding(binding);
        return "binding-ok";
    }
}
